# 导入模块
import json
import time
import requests
# 请求网址
i = 1
url = f'https://www.ptpress.com.cn/hotBook/getHotBookList?parentTagId=75424c57-6dd7-4d1f-b6b9-8e95773c0593&rows=20&page={i}'
response = requests.get(url)
print(response)
# 获取字符串类型的响应信息
datas = response.text
# 转成json格式的数据
json_datas = json.loads(datas)
data = json_datas['data']
rows = data['rows']
for row in rows:
    bookName = row['bookName']
    price = row['price']
    picPath = row['picPath']
    # 输出信息
    print('书名', bookName, '定价', price, '封面', picPath)
    url = f'{picPath}'
    response = requests.get(url)
    print(response)
    datas = response.content
    # print(datas)
    with open(f"image/{bookName}.jpg", "wb") as f:
        f.write(datas)
    time.sleep(0.1)

